package main

import (
	"fmt"
	"reflect"
	"strings"
)

func reverseWords(s string) string {

	strList := strings.Split(s, " ")
	fmt.Println(strList)
	fmt.Println(reflect.TypeOf(strList))
	var res []string
	for i := len(strList) - 1; i >= 0; i-- {
		str := strings.TrimSpace(strList[i])
		if len(str) > 0 {
			res = append(res, strList[i])
		}
	}
	fmt.Println(res)
	return strings.Join(res, " ")
}

func main() {
	s := " hello world tom "

	newS := reverseWords(s)
	fmt.Println(newS)
}
